<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\SaleService;
use App\Utility\Upload;
use Illuminate\Http\Request;

class SaleController extends BaseController
{
    //销售

    //列表
    public function index(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $pas['shop_id'] = $request->post('shop_id', 0);
        $res = SaleService::index($pages, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['plat_type'] = $request->post('plat_type', 0);
        $pas['shop_id'] = $request->post('shop_id', 0);
        $pas['intime'] = $request->post('intime', '');
        $pas['outtime'] = $request->post('outtime', '');
        if ($id) {
            $res = SaleService::modify($id, $pas);
        } else {
            $res = SaleService::add($pas);
        }
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = SaleService::del($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}